home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / csrc1.arc / GETHDR.C < prev    next >
C/C++ Source or Header  |  1989-07-27  |  2KB  |  58 lines

  1. /*--- EDIT # 0078    17 Apr 1982    0:33:10    DB1:[21,6]GETHDR.C;123  */
  2. /*--- PREVIOUS EDIT    18 Jan 1982    9:35:00    DB0:[310,105]GETHDR.C;122  */
  3. /* routine to read in a file-header. This is done by reading the
  4. index file in block-mode. */
  5. /* called with the directory file open. The index-file is re-opened on
  6.     this fp */
  7.  
  8. #include <stdio.h>
  9. #include <hdr.h>
  10.  
  11.  
  12. unsigned int index_offset = 0;    /* block number of fid=(1,1) */
  13.  
  14. gethdr (ib, fnum, fseq, dir)
  15. struct hdr *ib;
  16. unsigned int fnum, fseq;
  17. FILE *dir;
  18. {
  19.    int n;
  20.    char ixf_name [35];
  21.    char *d, *f;
  22.    long int file_pos;
  23. /* 1st word of home block is index bitmap size */
  24.  
  25.    if (!index_offset) {
  26. /* get the device name, then the rest of the filename */
  27.       iovtoa (dir, ixf_name);
  28.       d = ixf_name;
  29.       while (*d++ != ':') ;
  30.       f = "[0,0]INDEXF.SYS";
  31.       while (*d++ = *f++);
  32. /*fprintf (stderr,"Opening: %s\n", ixf_name);*/
  33.       if (!freopen(ixf_name, "runb", dir))
  34.      return (-1);    /* can't open the index-file */
  35. /* For the INDEX file, kludge up the fdb */
  36. /* The 1st word of the home-block (2nd block of the index-file) tells
  37. the number of blocks in the index bitmap, which is the offset for the
  38. file-headers. i can't quite figure out how to share the definition of
  39. "ib" betewwn the header and an array of words, so I did it this way,
  40. knowing that it will always be a small number. You should be able to
  41. just read 2 bytes into an integer, but virtual disks can't do that */
  42.       dir->io_fdb[2] = dir->io_fdb[4] = 077777;
  43.       fseek (dir,01000l, 0);    /* read the home block */
  44.       n = fget (ib, sizeof *ib, dir);
  45.       index_offset = 1 + ib->h_idof;
  46.    }
  47.  
  48.    /* read the desired file-header */
  49.    file_pos = 01000l * (index_offset + fnum);
  50.    fseek (dir, file_pos, 0);
  51.    n = fget (ib, sizeof *ib, dir);
  52.    if ((ib->h_fnum == fnum) &&
  53.     (ib->h_fseq == fseq))    return (0);
  54.    printf ("index_offset=%d\n", index_offset);
  55.    printf ("req, got: %o,%o   %o,%o\n", fnum, fseq, ib->h_fnum, ib->h_fseq);
  56.    return (-36);
  57. }
  58.